//
//  MyCustomCell.m
//  TUIKitDemo
//
//  Created by annidyfeng on 2019/6/10.
//  Copyright © 2019年 Tencent. All rights reserved.
//
/** 腾讯云IM Demo自定义气泡视图
 *  用于显示聊天气泡中的文本信息数据
 *
 */
#import "TUILinkCell.h"
#import <TUICore/TUIGlobalization.h>
#import <TUICore/TUIThemeManager.h>

@implementation TUILinkCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _myBackImageView = [[UIImageView alloc] init];
        [_myBackImageView setImage:TUIChatBundleThemeImage(@"chat_custom_evaluation_message_img", @"custem_chat_qianghongbao")];
        [self.container addSubview:_myBackImageView];

        
        _myTextLabel = [[UILabel alloc] init];
        _myTextLabel.numberOfLines = 0;
        _myTextLabel.font = [UIFont boldSystemFontOfSize:15];
        _myTextLabel.textColor = TUIChatDynamicColor(@"chat_link_message_title_color", @"#000000");
        [self.container addSubview:_myTextLabel];
        _myTextLabel.textAlignment = NSTextAlignmentCenter;

        _myLinkLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _myLinkLabel.text = TIMCommonLocalizableString(TUIKitMoreLinkDetails);
        _myLinkLabel.font = [UIFont systemFontOfSize:13];
        _myLinkLabel.textColor = TUIChatDynamicColor(@"chat_link_message_subtitle_color", @"#0000FF");
        [self.container addSubview:_myLinkLabel];
        _myLinkLabel.textAlignment = NSTextAlignmentCenter;
        
    }
    return self;
}

- (void)fillWithData:(TUILinkCellData *)data;
{
    [super fillWithData:data];
    self.customData = data;
    
    self.myTextLabel.text = data.text;

    if (data.direction == MsgDirectionIncoming) {
        self.myLinkLabel.text = [NSString stringWithFormat:@"%@赠送", data.link];
    }else {
        self.myLinkLabel.text = [NSString stringWithFormat:@"红包", data.link];
    }
    
    [self.bubbleView setHidden:YES];
    
    
    // tell constraints they need updating
    [self setNeedsUpdateConstraints];

    // update constraints now so we can animate the change
    [self updateConstraintsIfNeeded];

    [self layoutIfNeeded];
}


- (void)updateConstraints {
    [super updateConstraints];
    
    [self.myBackImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0,0,0,0));
    }];
    
    
    [self.myLinkLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.container).offset(30);
        make.left.mas_equalTo(5);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(25);
    }];
    
    [self.myTextLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.container).offset(55);
        make.left.mas_equalTo(5);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(50);
    }];
    
}

+ (BOOL)requiresConstraintBasedLayout {
    return YES;
}


- (void)layoutSubviews {
    [super layoutSubviews];
    
//    self.myBackImageView.mm_top(0).mm_left(0).mm_width(120).mm_height(140);
//    self.myLinkLabel.mm_sizeToFit().mm_left(5).mm_top(30).mm_width(110).mm_height(25);
//    self.myTextLabel.mm_top(50).mm_left(5).mm_width(110).mm_height(50);

}

+ (CGSize)getContentSize:(TUIMessageCellData *)data {
    return CGSizeMake(120, 140);
}

@end
